#include "ImaLogger.h"
#include <log4cpp/PropertyConfigurator.hh>

ImaLogger* ImaLogger::mpLogger = NULL;


ImaLogger* ImaLogger::getInstance(char* pLogConfFilename) {
	if(mpLogger == NULL) {
		mpLogger = new ImaLogger();
		mpLogger->init(pLogConfFilename);
	}
	return mpLogger;
}

ImaLogger::ImaLogger() {
}

bool ImaLogger::init(char* pLogConfFilename) {
	log4cpp::PropertyConfigurator::configure(pLogConfFilename);
	log4cpp::Category& rootCategory = log4cpp::Category::getRoot();
	mpRootCategory = &rootCategory;

	log4cpp::Category& category = 
		log4cpp::Category::getInstance(std::string("sub1"));
	mpCategory = &category;


	/*log4cpp::PropertyConfigurator::configure(initFileName);
	log4cpp::Category& root = log4cpp::Category::getRoot();

	log4cpp::Category& sub1 = 
		log4cpp::Category::getInstance(std::string("sub1"));

	log4cpp::Category& sub2 = 
		log4cpp::Category::getInstance(std::string("sub1.sub2"));

	root.warn("Storm is coming");

	sub1.debug("Received storm warning");
	sub1.info("Closing all hatches");

	sub2.debug("Hiding solar panels");
	sub2.error("Solar panels are blocked");
	sub2.debug("Applying protective shield");
	sub2.warn("Unfolding protective shield");
	sub2.info("Solar panels are shielded");

	sub1.info("All hatches closed");

	root.info("Ready for storm."); */

	//log4cpp::Category::shutdown();

	return 0;
}

//int ImaLogger::log(LOG_LEVEL loglevel, char* pLogMsg) {
//	switch(loglevel) {
//		case DEBUG:
//			mpCategory->debug(pLogMsg);
//			break;
//		case INFO:
//			mpCategory->info(pLogMsg);
//			break;
//		case NOTICE:
//			mpCategory->notice(pLogMsg);
//			break;
//		case WARN:
//			mpCategory->warn(pLogMsg);
//			break;
//		case ERROR:
//			mpCategory->error(pLogMsg);
//			break;
//		case ALERT:
//			mpCategory->alert(pLogMsg);
//			break;
//	}
//
//	return 0;
//}


ImaLogger::~ImaLogger() {
	log4cpp::Category::shutdown();
	mpRootCategory = NULL;
	mpCategory = NULL;
	mpLogger = NULL;
}



